//***********************************************************
//*
//* File:           DumbPlayer.java
//* Author:         Abhinav Kamra
//* Contact:        kamra@cs.columbia.edu
//* Update:         10/03/2004
//*
//* Description:    Dump player for Project 2.  Purely for
//*                 didactic purposes.
//*
//***********************************************************

package paths.g0;

import java.util.*;
import java.io.*;
import java.awt.*;
import java.awt.image.*;
import javax.imageio.*;

import paths.*;

public final class DumbPlayer implements IFCPlayer {

    static Random _random;
    static final String _CNAME = "Dumb Player";
    static final Color  _CCOLOR = new Color(0.8f, 0.2f, 0.4f);

    Maps _maps;
    ArrayList<City> cities;
    ArrayList<Link> links;
//    TimeFunction timeFunction;
    public void register(Maps __maps) throws Exception {
	    _maps = __maps;
	    cities = _maps.getCities();
	    links = _maps.getLinks();
	    //timeFunction = _maps.getTimeFunction();
    }

    public Move move() throws Exception {
	    BufferedImage image;

	    File file = _maps.getBackgroundImage();
	    
	    //to get the background image, do this
	    image = ImageIO.read(file);
	    
	    //get graphics to draw on the image.
	    Graphics2D g = image.createGraphics();

	    
	    g.setFont(new Font(g.getFont().getName(), Font.BOLD, 18));
	    
	    
	    Iterator<City> itCity = cities.iterator();
	    while(itCity.hasNext()){
	    	City city = itCity.next();
	    	System.out.println(city.name);
	    	if(_maps.getStart().equals(city)){
	    		g.setColor(Color.RED);
	    		g.drawString("Start: "+city.name, city.x, city.y);		    		
	    	}else{
	    		g.setColor(Color.GREEN);
	    		g.drawString(city.name, city.x, city.y);
	    	}
	    }

		g.setColor(Color.BLUE);
	    Iterator<Link> itLink = links.iterator();
	    //System.out.println("Travel times at midnight:");
	    while(itLink.hasNext()){
	    	Link l = itLink.next();
	    	System.out.println(l.src + " to "+l.dest);
	    	City src = getCityByName(l.src);
	    	City dest = getCityByName(l.dest);
	    	g.drawLine((int)src.x, (int)src.y, (int)dest.x, (int)dest.y);
	    }
	    
	    Move RET = new Move(image, "Dumb World Map");
	    return RET;
    }

    private City getCityByName(String name){
    	Iterator<City> it = cities.iterator();
    	while(it.hasNext()){
    		City city = it.next();
    		if(name.equalsIgnoreCase(city.name))
    			return city;
    	}
    	return null;
    }
    
    public String name() throws Exception {
        return _CNAME;
    }

    public Color color() throws Exception {
        return _CCOLOR;
    }

    public boolean interactive() throws Exception {
        return false;
    }        

}
